<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        let loginList = [
            { userName: 'admin', password: 'admin321' },
            { userName: 'zhangsan', password: 'zs321' },
            { userName: 'lisi', password: 'ls321' },
            { userName: 'yyqx', password: 'yyqx321' }
        ]

        let userInfo = {
            token1: {
                city: '杭州',
                money: '1000w',
                sex: '女',
                userName: 'admin',
                password: 'admin321'
            },
            token2: {
                city: '北京',
                money: '1100w',
                sex: '女',
                userName: 'zhangsan',
                password: 'zs321'
            },
            token3: {
                city: '北京',
                money: '800w',
                sex: '男',
                userName: 'lisi',
                password: 'ls321'
            },
            token4: {
                city: '天津',
                money: '600w',
                sex: '男',
                userName: 'yyqx',
                password: 'yyqx321'
            }
        }


        function getNumber() {
            while (true) {
                let uname = prompt('请输入用户名')
                let password = prompt('请输入密码')
                for (let i = 0; i < loginList.length; i++) {
                    //console.log(loginList[i]);
                    if (uname !== loginList[i].userName && password !== loginList[i].password) {
                        let select = prompt(`账户不存在：
                        1.注册账号
                        2.直接退出`)
                        if (select === '1') {
                            let add = { userName: uname, password: password }
                            loginList.push(add)
                            console.log(loginList);
                            console.log(add)
                            uname = prompt('请输入用户名')
                            password = prompt('请输入密码')
                            alert('你已经注册成功，请直接登录')
                            uname = prompt('请输入用户名')
                            password = prompt('请输入密码')
                            if (uname !== add.userName || password !== add.password) {
                                alert('输错啦，你已经没机会了，退出登录')
                                break
                            }
                            // break
                        } else {
                            alert('退出了')
                            break
                        }
                    } else {
                        let res = 'token' + (Math.floor(Math.random() * 4) + 1)
                        console.log(res);
                        for (let token in userInfo) {
                            //console.log(token);// token1 --- token4
                            let users = userInfo[token]
                            if (res === token) {
                                alert(`登录成功，具体用户信息：
                          city:${userInfo[token].city}
                          money:${userInfo[token].money}
                          sex:${userInfo[token].sex}
                          userName:${uname}`)
                            }
                        }
                        //break
                    }
                    break
                }
                break

            }
        }

        getNumber();
    </script>
</body>

</html>